﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZX.BLL.Extend;
using ZX.CRM.Library;
using ZX.DAL.DBExtend;
using System.Data;

namespace ZX.CRM.Bussiness
{
    public class BCrmProductLayout : BaseBussnies
    {
        public DataTable GetProductLayoutYear()
        {
            DataTable dt = new DataTable();
            try
            {
                string strSql = string.Format("select distinct Left(CONVERT(nvarchar(50),BeginDate,121),4) from CrmProductLayout");
                DbSql db = new DbSql();
                dt = db.ExecuteQuery(strSql);
            }
            catch
            {
                dt = new DataTable();
            }
            return dt;
        }

        /// <summary>
        /// 获取产品
        /// </summary>
        /// <param name="TypeId"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public IList<V_CrmProductLayout> GetProductLayout(Guid TypeId, Guid UserId)
        {
            this.entity = new V_CrmProductLayout();
            return this.GetEntitysBySqlComm<V_CrmProductLayout>("select distinct [Caption],[ProductID],[TypeId],[UserId] " +
                                            " from V_CrmProductLayout where TypeId='" + TypeId + "' and UserId='" + UserId + "'" +
                                            " group by [BeginDate],[Caption],[ProductID],[TypeId],[UserId]");
        }
        /// <summary>
        /// 根据用户ID获取产品期数
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public IList<V_CrmProductLayout> GetProductLayoutByUserId(Guid UserId)
        {
            this.entity = new V_CrmProductLayout();
            return this.GetEntitysBySqlComm<V_CrmProductLayout>("select * from V_CrmProductLayout where UserId='" + UserId + "'");
        }
        /// <summary>
        /// 根据课程规划ID获取产品期数
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public IList<V_CrmProductLayout> GetProductLayoutByProductLayoutId(Guid ProductLayoutId)
        {
            this.entity = new V_CrmProductLayout();
            return this.GetEntitysBySqlComm<V_CrmProductLayout>("select * from V_CrmProductLayout where ProductLayoutId='" + ProductLayoutId + "'");
        }

        /// <summary>
        /// 获取学员信息
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public IList<V_CrmDeliverMajorStudent> GetCrmDeliverMajorStudent(Guid LayoutId)
        {
            this.entity = new V_CrmDeliverMajorStudent();
            return this.GetEntitysBySqlComm<V_CrmDeliverMajorStudent>("select * from V_CrmDeliverMajorStudent where ProductLayoutID='" + LayoutId + "'");
        }
        /// <summary>
        /// 打印学员信息
        /// </summary>
        /// <param name="printType"></param>
        /// <param name="imgType"></param>
        /// <param name="LayoutId"></param>
        /// <param name="groupName"></param>
        /// <param name="deptName"></param>
        /// <param name="IsTrain"></param>
        /// <returns></returns>
        public IList<V_CrmDeliverMajorStudent> GetCrmDeliverMajorStudentToPrint(string printType, string imgType, Guid LayoutId, string groupName, string deptName, int IsTrain)
        {
            this.entity = new V_CrmDeliverMajorStudent();
            string strSql = string.Format("select * from V_CrmDeliverMajorStudent where ProductLayoutID='" + LayoutId + "'");
            if (printType == "1" && imgType != "3")  //默认打印并且不打印助教/辅导员
            {
                if (groupName != "")
                {
                    strSql += " and GroupName like '%" + groupName + "%'";
                }
                if (deptName != "")
                {
                    strSql += " and OrderofDeptName like '%" + deptName + "%'";
                }
                strSql += " and IsTrain='" + IsTrain + "'"; //0:不是复训 1:是复训
            }
            strSql += " and GroupName<>0 order by OrderofDeptName,GroupNumber";
            return this.GetEntitysBySqlComm<V_CrmDeliverMajorStudent>(strSql);
        }

        /// <summary>
        /// 获取期初数据信息
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public IList<V_CrmLayoutRecordProducts> GetCrmLayoutRecordProducts(Guid recordId)
        {
            this.entity = new V_CrmLayoutRecordProducts();
            return this.GetEntitysBySqlComm<V_CrmLayoutRecordProducts>("select * from V_CrmLayoutRecordProducts where LayoutRecordId='" + recordId + "'");
        }
    }
}
